package com.example.myapplication

import android.content.Intent
import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat

class PageOne : AppCompatActivity() {
    // 定义一个常量
    private val TAG = "itHeiMa"
    override fun onCreate(savedInstanceState: Bundle?) {
        Log.d(TAG, "onCreate")
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        setContentView(R.layout.activity_page_one)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }
        // 1. 获取到按钮
        val btn = findViewById<View>(R.id.btn_action_next)
        btn.setOnClickListener {
            // 2. 创建 Intent 并指定目标 Activity
            // 这段代码的作用是创建一个新的Intent(意图)对象，跳转到PageTwoActivity页面
            // this表示当前Activity上下文
            // PageTwoActivity::class.java表示要跳转的目标Activity类
            val intent = Intent(this, PageTwo::class.java)

            // 3. 添加附加数据
            intent.putExtra("user_name", "张三")
            intent.putExtra("user_age", 25)

            // 4. 启动Activity跳转
            startActivity(Intent(intent))
        }
    }

    override fun onStart() {
        super.onStart()
        Log.d(TAG, "onStart")
    }

    override fun onResume() {
        super.onResume()
        Log.d(TAG, "onResume")
    }

    override fun onPause() {
        super.onPause()
        Log.d(TAG, "onPause")
    }

    override fun onStop() {
        super.onStop()
        Log.d(TAG, "onStop")
    }

    override fun onDestroy() {
        super.onDestroy()
        Log.d(TAG, "onDestroy")
    }

    override fun onRestart() {
        super.onRestart()
        Log.d(TAG, "onRestart")
    }
}